<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加数据</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link href="../../../public/css/index-php-style.css" rel="stylesheet" />
    <script>
        // 禁用浏览器缓存
        if (window.history.replaceState) {
            window.history.replaceState(null, null, window.location.href);
        }
    </script>
    <style>
        body {
            background-color: #f2f3f5;
            padding-top: 6rem;
        }

        .navbar {
            background-color: #fff !important;
        }

        .container-box {
            background-color: #fff;
            border-radius: 5px;
            overflow: hidden;
            padding-top: 3rem;
            padding-bottom: 3rem;
        }

        .container .con-h2 {
            text-align: left;
            color: #252933;
            padding-bottom: 1rem;
            border-bottom: 1px solid #e4e6eb;
            font-size: 16px;
        }

        .container form label {
            display: block;
            margin-bottom: 5px;
            color: #333;
            font-weight: bold;
            margin-top: 1rem;
        }

        .container form input[type="text"],
        .container form textarea {
            width: 100%;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 4px;
            box-sizing: border-box;
            margin-bottom: 10px;
            color: #333;
        }

        .container form textarea {
            height: 100px;
        }

        .container form button {
            display: block;
            width: 100%;
            padding: 10px;
            background-color: #1e80ff;
            color: #fff;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        .container form button:hover {
            background-color: #1171ee;
            color: #fff;
        }
    </style>
</head>

<body>
    <!-- 引入nav导航栏 -->
    <?php require '../../../nav.php'; ?>

    <div class="container container-box">
        <div class="con-h2">编辑文章(添加的文章会在首页列表中展示)</div>
        <form action="../controllers/addcontent.php" method="post">
            <label for="title">文章标题(不可为空)：</label>
            <input type="text" id="title" name="title" required>

            <label for="message">文章内容(不可为空)：</label>
            <textarea id="message" name="message" required></textarea>

            <button type="submit" class="btn">添加文章</button>
        </form>
    </div>

    <script src="../../../public/js/jquery-3.7.0.min.js"></script>
    <script src="../../../public/js/bootstrap.bundle.min.js"></script>
    <script>
        $(".btn").on('click', function() {
            if ($("#title")[0].value.trim() == '') {
                alert('文章标题不能为空！');
            } else if ($("#message")[0].value.trim() == '') {
                alert('文章内容不能为空！');
            }
        });
    </script>
</body>

</html>